package com.itheima.app.controller.pmsController;

import com.itheima.app.manager.pmsManager.BrandManager;
import com.itheima.commons.R;
import com.itheima.domain.db.pms.PmsBrand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class BrandController {

    @Autowired
    BrandManager brandManager;

    //根据品牌名称分页获取品牌列表
    @GetMapping("/brand/list")
    public R getbrandList(String keyword, Integer pageNum, Integer pageSize) {

        return brandManager.getBrandList(keyword, pageNum, pageSize);
    }

    //添加品牌
    @PostMapping("/brand/create")
    public R createBrand(@RequestBody PmsBrand brand) {

        return brandManager.saveBrand(brand);
    }

    //批量删除品牌
    @PostMapping("/brand/delete/batch")
    public R deleteBrand(@RequestParam List<Long> ids) {

        return brandManager.deleteBrand(ids);
    }

    //删除品牌
    @GetMapping("/brand/delete/{id}")
    public R deliteById(@PathVariable Integer id) {
        return brandManager.deleteById(id);
    }

    //获取全部品牌列表
    @GetMapping("/brand/listAll")
    public R brandListAll() {
        return brandManager.listAll();
    }

    //批量更新厂家制造商状态
    @PostMapping("/brand/update/factoryStatus")
    public R updateFactoryStatus(Integer factoryStatus, Integer[] ids) {

        return brandManager.updateFactoryStatus(factoryStatus, ids);
    }

    //批量更新显示状态
    @PostMapping("/brand/update/showStatus")
    public R updateShowStatus(Integer showStatus, Integer[] ids) {

        return brandManager.updateShowStatus(showStatus,ids);
    }

    //更新品牌
    @PostMapping("/brand/update/{id}")
    public R updateById(@PathVariable Long id ,@RequestBody PmsBrand brand){
        brand.setId(id);
        return brandManager.updateById(brand);
    }

    //根据编号查询品牌信息
    @GetMapping("/brand/{id}")
    public R brandById(@PathVariable Long id){
        return brandManager.getById(id);
    }
}
